<template>
  <view class="content">
    <!-- 头部 -->
    <view class="header">
      <view class="header-info">
        <view class="headerimg">
          <img class="user-avatar" src="https://img2.baidu.com/it/u=891414272,1661227786&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800" />
        </view>
        <view class="user-info">
          <view>手机号码:{{currentUser.phone}}</view>
          <view>ID:{{currentUser.id || '123456'}}</view>
        </view>
      </view>
    </view>
    <!-- 中间 -->
    <view class="middle">
      <view class="middlelist">
        <view class="middleitem" @click="myaddress">
          <view class="icon-container">
            <img class="menu-icon" src="/static/imgs/addressme.png" />
          </view>
          <view class="item-text">我的地址</view>
        </view>
        <view class="middleitem">
          <view class="icon-container">
            <img class="menu-icon" src="/static/imgs/loveme.png" />
          </view>
          <view class="item-text">我的关注</view>
        </view>
        <view class="middleitem">
          <view class="icon-container">
            <img class="menu-icon" src="/static/imgs/cartme.png" />
          </view>
          <view class="item-text">我的订单</view>
        </view>
      </view>
    </view>
    <!-- 底部 -->
    <view class="middlelogin">
      <button type="primary" @click="logout" class="logout-button">退出登录</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentUser: {} // 当前登录用户信息
    };
  },
  onLoad() {},
  onShow() {
    // 从本地存储加载当前用户信息
    const user = uni.getStorageSync('currentUser');
    if (user) {
      this.currentUser = user;
    } else {
      // 如果未登录，跳转到登录页面
      uni.redirectTo({
        url: '/pages/login/login'
      });
    }
  },
  methods: {
    message() {
      uni.request({
        url: `http://localhost:3000/users`,
        success: (res) => {
          this.users = res.data;
        }
      });
    },
    // 退出登录
    logout() {
      uni.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            // 清除用户信息
            uni.removeStorageSync('currentUser');
            // 跳转到登录页面
            uni.redirectTo({
              url: '/pages/login/login'
            });
          }
        }
      });
    },
    myaddress() {
      uni.navigateTo({
        url: '/pages/own/myaddress'
      });
    }
  }
};
</script>

<style scoped>
/* 通用图片样式 */
img {
  display: block;
  max-width: 100%;
  height: auto;
  object-fit: cover;
}

/* 用户头像 */
.user-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  border: 2px solid white;
}

/* 菜单图标 */
.menu-icon {
  width: 25px;
  height: 25px;
}

/* 整体内容 */
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f4f4f4;
  min-height: 100vh;
}

/* 头部 */
.header {
  width: 100%;
  height: 220px;
  background-color: #6daff7;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.headerimg {
  margin-bottom: 15px;
}

.user-info {
  font-size: 14px;
  line-height: 1.6;
}

/* 中间 */
.middle {
  width: 100%;
  padding: 15px 0;
  margin-top: -30px;
}

.middlelist {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 90%;
  margin: 0 auto;
}

.middleitem {
  display: flex;
  align-items: center;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 15px;
  transition: all 0.3s ease;
}

.middleitem:active {
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.icon-container {
  margin-right: 15px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-text {
  font-size: 16px;
  font-weight: 500;
}

/* 底部 */
.middlelogin {
  width: 100%;
  text-align: center;
  margin-top: 20px;
  padding-bottom: 20px;
  padding: 0 20px;
}

.logout-button {
  background-color: #ff4d43;
  border: none;
  color: white;
  padding: 10px 0;
  border-radius: 25px;
  font-size: 16px;
  width: 100%;
  max-width: 300px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logout-button:active {
  background-color: #E7352C;
}

/* 响应式调整 */
@media (max-width: 375px) {
  .user-avatar {
    width: 70px;
    height: 70px;
  }
  
  .menu-icon {
    width: 22px;
    height: 22px;
  }
  
  .item-text {
    font-size: 15px;
  }
  
  .header {
    height: 200px;
  }
}
</style>